package gamebackend;
import framework.Color;
import generators.BasicBlockGenerator;
import generators.BlockRule;
import generators.EmbiggenGenerator;
import generators.HorizontalStreakGenerator;
import generators.PipeGenerator;
import generators.ScaredGenerator;
import generators.SquareGenerator;
import generators.VerticalScaredGenerator;
import generators.VerticalStreakGenerator;
import gui.BlockStyle;

import java.util.Random;



public class ButterCaveBiome extends GameSession.Biome {
	public static final int CHANGE_LENGTH = 1000;
	private static final int EASY_WIDTH = 30;
	private static final int HARD_WIDTH = 7;
	
	private double my_distanceToChange;
	private StutterFlier my_easyStutter;
	private StutterFlier my_hardStutter;
	public ButterCaveBiome(GameSession the_session,
			int the_tier, Random the_random, double the_length) {
		the_session.super(the_session, the_tier, the_random, the_length);
		addEasyPath(new FlightPath(Block.PRIMARY_PATH, getEasyPath(), EASY_WIDTH), getLength());
		addHardPath(new FlightPath(Block.SECONDARY_PATH, getHardPath(), HARD_WIDTH + 6 * (2 - getTier())), getLength());
//		addGenerator(new BasicBlockGenerator(new Block(BlockStyle.THORN, Color.GRAY), Block.EMPTY_BLOCK, the_random, 1), the_length);
		final Block block = new Block(BlockStyle.ASTEROID, new Color(230, 210, 130));
		addGenerator(new VerticalScaredGenerator(block, getRandom(), .04 - getTier() * .015), getLength());
		addGenerator(new VerticalStreakGenerator(getRandom(), .85 + .04 * getTier()), getLength());
		addGenerator(new BasicBlockGenerator(block, Block.EMPTY_BLOCK, getRandom(), 1), 80);
		
		final Block back = new Block(BlockStyle.ASTEROID,
				new Color(40, 35, 20));
		addToMidGround(new BasicBlockGenerator(back, Block.SECONDARY_PATH, getRandom(), .4), getLength());
		addToMidGround(new VerticalStreakGenerator(back, getRandom(), .92), getLength());
		
		
		my_easyStutter = new StutterFlier(getEasyPath().getShipFlier(),getWidth() / 3);
		my_hardStutter = new StutterFlier(getHardPath().getShipFlier(),getWidth() / 7);
		MultiFlier multi = new MultiFlier();
		setFlier(multi);
		final double width = getWidth() * .9 / 4;
		multi.add(new RestlessFlier(
				
				my_easyStutter,
				getRandom(), width, getWidth(), 0, getWidth()
			));
		multi.add(new RestlessFlier(
				
				my_hardStutter,
				getRandom(), width, getWidth(), 0, getWidth()
			));
		
//		final DirectFlier direct =new DirectFlier(new TogetherFlier(getHardPath().getShipFlier(), getEasyPath().getShipFlier(), getWidth() / 8));
//		direct.setTarget(50);
//		multi.add(direct);
		//multi.add(new RestlessFlier(new StutterFlier(new StutterFlier(getEasyPath().getShipFlier(), getWidth() / 6), getWidth() / 4), getRandom(), 0, getWidth()));
		//multi.add(new RestlessFlier(getHardPath().getShipFlier(), getRandom(), 0, getWidth()));
	}
	@Override
	public void step(final double the_yChange) {
		super.step(the_yChange);
		my_distanceToChange -= the_yChange;
		if (my_distanceToChange < 0) {
			
			if (my_easyStutter.getStutterWidth() == getWidth() / 3) {
				my_easyStutter.setStutterWidth(getWidth());
				my_hardStutter.setStutterWidth(getWidth() / 2);
				my_distanceToChange += CHANGE_LENGTH / 2;
			} else {
				my_easyStutter.setStutterWidth(getWidth() / 3);
				my_hardStutter.setStutterWidth(getWidth() / 7);
				my_distanceToChange += CHANGE_LENGTH;
			}
		}
	}
	
	public void flierTestStep(final double the_yChange) {
		super.step(the_yChange);
		my_distanceToChange -= the_yChange;
		if (my_distanceToChange < 0) {
			my_distanceToChange += CHANGE_LENGTH;
			MultiFlier multi = new MultiFlier();
			
			
			Flier easy = getEasyPath().getShipFlier();
			if (getRandom().nextDouble() < .2) {
				easy = new StutterFlier(easy, getWidth() / 6);
			}
			if (getRandom().nextDouble() < .2) {
				easy = new StutterFlier(easy, getWidth() / 3);
			}
			
			
			Flier hard = getHardPath().getShipFlier();
			if (getRandom().nextDouble() < .2) {
				hard = new StutterFlier(hard, getWidth() / 4);
			}
			
			if (getRandom().nextDouble() < .8) {
				multi.add(new EasyFlier(easy, getRandom(), 0, getWidth()));
				multi.add(new EasyFlier(hard, getRandom(), 0, getWidth()));
			} else {
				Flier together = new TogetherFlier(easy, hard, 40);
				if (getRandom().nextDouble() < .2) {
					together = new StutterFlier(together, getWidth() / 3);
				}
				multi.add(new RestlessFlier(together, getRandom(), 0, getWidth()));
			}
			
			
			
			
			
			setFlier(multi);
		}
		

		
			
		
		
	
		
		
				
	}
}